Skip to main content

Project Configuration (kconfig / sdkconfig)

KConfig is utilized by ESP-IDF to create a configuration for the project build. Details about project configuration from esp-idf documentation can be found here.

All ESP-IDF projects include a default menu or menuconfig. In our projects, we add new menus to the default menuconfig

Assuming you are using ESP-IDF extension over VS-Code, menuconfig UI can be launched by:

  1. From command palate:
    command palate

  2. Clicking on the cogwheel icon on the bottom toolbar.
    cog wheel

  3. Via the shortcut, ctrl+E and then G

menuconfig looks like following.

menuconfig

Files of importance

  1. main > Kconfig.projbuild Definitions for custom menus go here.
  2. sdkconfig This is auto-generated every time the project is built after an entry is changed in the menuconfig.
  3. sdkconfig.defaults This file is is used to set the default values for menuconfig parameters explicitly.

Apart from the files above which are standard files in a ESP-IDF project, we include a template for the sdkconfig.defaults, namely Template_sdkconfig.defaults. This is the template that each user should rename to sdkconfig.defaults and add the local parameter values before building the project.

Add / modify a custom menu entry

  1. Open the main > Kconfig.projbuild file.
    kconfig.projbuild

  2. Syntax. Easiest way would be to check the existing entries in the kconfig.projbuild file and duplicate it.

    1. Each menu goes between menu and endmenu tags.

    2. Mostly used datatypes are bool, int and strings.

    3. Examples:

      1. A dropdown menu with bool values

        choice
        bool "Mesh Topology"
        default MESH_TOPO_TREE
        help
        Mesh Network Topology.

        config MESH_TOPO_TREE
        bool "MESH_TOPO_TREE"
        config MESH_TOPO_CHAIN
        bool "MESH_TOPO_CHAIN"
        endchoice
      2. An int value based on the values selected above

            config MESH_TOPOLOGY
        int
        default 0 if MESH_TOPO_TREE
        default 1 if MESH_TOPO_CHAIN
        help
        Mesh Network Topology.
      3. A string field

        config MESH_ROUTER_SSID
        string "Router SSID"
        default "ROUTER_SSID"
        help
        Router SSID.
    4. Controller directives. You can enable and disable menu sections based on the values selected on other parameters. Check the following example which uses depends on directive on the second parameter.

          config ENABLE_BATT_VOLTAGE_CHECK
      bool "Enable battery voltage check"
      default y
      help
      Untick this box to disable battery voltage checking

      config BATTERY_VOLTAGE_CUTOFF_MV
      int "Battery voltage cutoff in mV"
      depends on ENABLE_BATT_VOLTAGE_CHECK
      range 0 3600
      default 3000
      help
      Battery voltage cutoff in mV
  3. The parameters you define in the Kconfig.projbuild, can be used as precompile directives in the code with CONFIG_ prefix. For example, the Kconfig.projbuild if the parameter name is MESH_ROUTER_SSID, that can be accessed in the C code as CONFIG_MESH_ROUTER_SSID.

  4. Each time you make a change in Kconfig.projbuild, delete the sdkconfig file manually in-order for new changes to appear on the menuconfig